package server;

import java.util.ArrayList;
import java.util.List;
 
import org.restlet.resource.ServerResource;
 
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;
import DBO.Contact;
	 
	public class UserControl extends ServerResource implements UserControlInterface {
	 
	 public UserControl() {
	 }
	 
	 @Override
	 public void create(Contact Contact) {
		 ObjectifyService.register(Contact.class);
		 Objectify ofy = ObjectifyService.begin();
		 
		 Contact tp = new Contact();
		 tp.setFirstname(Contact.getFirstname());
		 tp.setLastname(Contact.getLastname());
		 tp.setNickname(Contact.getNickname());
		 ofy.put(tp);
	 }
	 
	 @Override
	 public Container getAllContacts() {
		 Container content = null;
		 List<Contact> Contacts = new ArrayList<Contact>();
		 ObjectifyService.register(Contact.class);
		 Objectify ofy = ObjectifyService.begin();
		 
		 Query<Contact> q = ofy.query(Contact.class);
		 
		for (Contact u : q)
		    Contacts.add(u);
		 
		 content = new Container();
		 content.setUser_list(Contacts);
		 
		 return content;
	 }
}